//
//  ByUISceneShapeMakeView.m
//  laserdevice_ios
//
//  Created by pro on 16/11/25.
//  Copyright © 2016年 com.itboye. All rights reserved.
//

#import "ByUISceneShapeMakeView.h"

@implementation ByUISceneShapeMakeView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupViews];
    }
    
    return self;
}

- (void)setupViews {
    
    NSArray *texts = @[STRING(@"zhixian"),
                       STRING(@"jiaoduxian"),
                       STRING(@"sanjiaoxing"),
                       STRING(@"zhengfangxing"),
                       STRING(@"tixing"),
                       STRING(@"changfangti"),];
    NSArray *images = @[@"scene_zhixian",
                        @"scene_jiaodu",
                        @"scene_sanjiaoxing",
                        @"scene_zhengfangxing",
                        @"scene_tixing",
                        @"scene_changfangti"];
    // 循环创建
    CGFloat margin = 5;
    
    for (int i = 0; i < texts.count; i ++) {
        CGFloat width = self.width / texts.count;
        CGFloat height = self.height;
        CGFloat x = i * width;
        CGFloat y = 0;
        UIControl *mixView = [[UIControl alloc] init];
        mixView.frame = CGRectMake(x, y, width, height);
        [mixView addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:mixView];
        mixView.tag = i;
        
        // 图片
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
        imgView.image = [UIImage imageNamed:images[i]];
        
        // 文字
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 16)];
        label.adjustsFontSizeToFitWidth = YES;
        label.font = FONT(15);
        label.text = texts[i];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor whiteColor];
        
        [mixView addSubview:imgView];
        [mixView addSubview:label];
        
        // 设置位置
        CGFloat remainY = mixView.height - imgView.height - label.height - margin;
        imgView.top = remainY / 2;
        imgView.x = mixView.width / 2;
        label.top = imgView.bottom + margin;
        
        
    }

}



- (void)tapAction:(UIControl *)sender {
    
    if (self.didSelectShape) {
        self.didSelectShape(sender.tag);
    }
}
@end
